<template>
  <div class="app-container">
    <el-form :model="form" ref="form" :inline="true">
      <el-form-item label="移库状态" prop="orderStatus">
        <el-input v-model="form.orderStatus" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="移库单号" prop="orderNo">
        <el-input v-model="form.orderNo" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-button type="primary" v-hasPermi="['ims:moveStore:add']" plain icon="el-icon-plus" @click="updateRow(0,{})">
      新增
    </el-button>
    <el-table
      v-loading="loading"
      :data="list"
    >
      <el-table-column type="index" label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ (form.pageNum - 1) * form.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="orderNo" label="移库单号" align="center">
        <template slot-scope="scope">
          <el-link type="primary" @click="updateRow(1,scope.row)">{{ scope.row.orderNo }}</el-link>
        </template>
      </el-table-column>
      <el-table-column prop="warehouseName" label="源仓库" align="center"/>
      <el-table-column prop="warehouseName" label="目标仓库" align="center"/>
      <el-table-column prop="totalQuantity" label="总数量" align="center"/>
      <el-table-column prop="totalAmount" label="总金额" align="center"/>
      <el-table-column prop="orderStatus" label="移库状态" align="center"/>
      <el-table-column prop="createName" label="操作人" align="center"/>
      <el-table-column prop="createTime" label="操作时间" align="center"/>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="updateRow(1,scope.row)"
          >详情
          </el-button>
          <el-button
            type="text"
            v-hasPermi="['ims:moveStore:update']"
            @click="updateRow(2,scope.row)"
          >修改
          </el-button>
          <el-button
            type="text"
            v-hasPermi="['ims:moveStore:delete']"
            @click="updateRow(3,scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" :page.sync="form.pageNum" :limit.sync="form.pageSize" @pagination="getList"/>
    <updateDialog ref="updateDialog" @ok="handleQuery"></updateDialog>
  </div>
</template>

<script>
import {deleteMoveStore, listMoveStore} from "../../../../api/imsMng";
import updateDialog from "./updateDialog.vue";

export default {
  name: 'OutStore',
  components: {updateDialog},
  data() {
    return {
      loading: false,
      listShow: true,
      tabIndex: 0,
      selectList: [],
      list: [],
      form: {
        brandName: '',
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      goodTypeList: [],
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      this.handleQuery()
    },
    handleQuery() {
      this.form.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.handleQuery()
    },
    getList() {
      this.loading = true
      listMoveStore(this.form).then(res => {
        this.list = res.rows
        this.total = res.total
      }).finally(e => {
        this.loading = false
      })
    },
    updateRow(flag, row) {
      if (flag != 3) {
        let form = JSON.parse(JSON.stringify(row))
        this.$refs.updateDialog.show(flag, form)
      } else {
        this.$modal.confirm('是否确定删除').then(() => {
          deleteMoveStore(row.id).then(res => {
            this.handleQuery()
            this.$message.success('删除成功')
          })
        })
      }
    }
  }
}
</script>
